#pragma once
#include <memory>
#include <string>
#include "lvgl.h"
namespace Media{

#define LV_WIDTH 1920
#define LV_HEIGHT 1080
#define DISP_BUF_SIZE LV_WIDTH*LV_HEIGHT

typedef struct{
    std::string m_device_name;
    std::string m_share_code;
    std::string m_ap_name;
    std::string m_ap_password;
    std::string m_wifi;
    std::string m_eth_ip;
    bool m_actived;
}DisplayInfo;


typedef enum{
    None,
    Default,
    Osd,
    HideOsd,
}DisplayState;

typedef enum{
    WIFIWARN  = 0x00000001,
	USBDISKWARN = 0x00000002
}WarnPrompt;

class GuiDisplay{
public:
    using Ptr = std::shared_ptr<GuiDisplay>;
    static Ptr Instance();
    GuiDisplay();
    ~GuiDisplay();

    bool LedStatusWarn();

    void SetDisplayInfo(const std::string& device_name, const std::string& share_code, 
        const std::string& ap_name, const std::string& password, const std::string& wifi,
        const std::string& eth_ip);

    void DisplayDefaultDigitalSignage();
    void DisplayOsd();

    void DisplayWarnSD();
    void CloseDisplayWarnSD();

    void DisplayWarnWifi();
    void CloseDisplayWarnWifi();
    
    void Update();
    void SwitchDisplay();
    void ReloadHomeScreen();
    void playDailySchedule();
private:
    void init();
    void run();
    void loadDisplayInfo(bool& needUpdate);
    void fontInit();
    void showWarnPrompt();
    void showDailySchedule();

    lv_obj_t * create_custom_label(lv_obj_t * parent, const char * text, 
            lv_style_t* style_font, lv_font_t* font, lv_coord_t x, lv_coord_t y, lv_color_t color = lv_color_white());
    lv_disp_draw_buf_t m_disp_buf;
    lv_color_t m_buf[DISP_BUF_SIZE];
    // lv_color_t m_buf2[DISP_BUF_SIZE];
    lv_disp_drv_t m_disp_drv;
    lv_obj_t * m_obj = nullptr;

    lv_obj_t *m_device_name_lb = nullptr;
    lv_obj_t *m_share_code_lb = nullptr;
    lv_obj_t *m_ap_name_lb = nullptr;
    lv_obj_t *m_password_lb = nullptr;
    lv_obj_t *m_wifi_lb = nullptr;
    lv_obj_t *m_eth_ip_lb = nullptr;
    lv_obj_t *m_actived_lb = nullptr;
    lv_obj_t *m_osd_lb = nullptr;
    lv_obj_t *m_sd_error_lb = nullptr;
    lv_obj_t *m_wifi_error_lb = nullptr;

    lv_style_t m_device_name_lb_style;
    lv_style_t m_share_code_lb_style;
    lv_style_t m_ap_name_lb_style;
    lv_style_t m_password_lb_style;
    lv_style_t m_wifi_lb_style;
    lv_style_t m_eth_ip_lb_style;
    lv_style_t m_actived_lb_style;
    lv_style_t m_osd_lb_style;
    lv_ft_info_t m_osd_font_info;
    lv_ft_info_t m_default_font_info;
    lv_ft_info_t m_name_font_info;

    std::string m_device_name_lb_text;
    std::string m_share_code_lb_text;
    std::string m_ap_name_lb_text;
    std::string m_password_lb_text;
    std::string m_wifi_lb_text;
    std::string m_eth_ip_lb_text;
    std::string m_osd_lb_text;
    bool        m_actived = false;
    
    std::mutex  m_dailyLock;
    bool        m_dailySchedule = false;

    DisplayInfo m_osd_info;

    DisplayState m_state = None;

    std::atomic<unsigned int> m_warnSatus = 0;
    std::atomic<bool> m_warnSatusChange = true;
    bool m_customHomeScreen = false;
    bool m_reloadImg = false;
};

}